package yxy.cherry.data.dfa;

import java.util.List;

import org.redisson.api.RList;

import yxy.apple.util.redisson.RedisConnection;

/** 敏感词过滤 */
public class Sensitive {
	static private Sensitive instance;

	static public void init(RedisConnection connection) {
		if (instance == null) {
			instance = new Sensitive();

			RList<String> rlist = connection.client().getList("SENSITIVE:WORDS");
			List<String> list = rlist.readAll();

			for (String word : list) {
				instance.dfa.addWord(word);
			}
		}
	}

	private Sensitive() {
	}

	private Dfa dfa = new Dfa();

	public static boolean isSensitive(String word) {
		if (instance == null) {
			return false;
		}
		return instance.dfa.isSensitive(word);
	}
}
